package com.reger.l2cache.annotation;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.config.AopConfigUtils;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

class L2CacheRegistrar implements ImportBeanDefinitionRegistrar {

	private static final Logger log = LoggerFactory.getLogger(L2CacheRegistrar.class);

	public final static String ENABLEL2CACHEANNOTATION="com.reger.l2cache.annotation.EnableL2Cache";
	
	@Override
	public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
		Map<String, Object> enableL2CacheMap = annotationMetadata.getAnnotationAttributes(ENABLEL2CACHEANNOTATION);
		if ((Boolean)enableL2CacheMap.get("proxyTargetClass")) {
			AopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry);
			log.debug("aop开启类代理");
		}
		if ((Boolean)enableL2CacheMap.get("exposeProxy")) {
			AopConfigUtils.forceAutoProxyCreatorToExposeProxy(registry);
			log.debug("aop开启方法内代理");
		}
	}
	
}
